import Vue from 'vue'
import VueRouter from 'vue-router'
import home from '@/views/Home.vue'
import city from '@/views/home/citys.vue'
import world from '@/views/World.vue'
import my from '@/views/My.vue'
import more from '@/views/home/more.vue'
import publish from '@/views/world/publish.vue'
import search from '@/views/home/search.vue'
import detail from '@/views/world/detail.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'*',
    redirect:'/home'
  },
  {
    path:'/home',
    component:home
  },
  {
    path:'/city',
    component:city
  },
  {
    path:'/world',
    component:world
  },
  {
    path:'/my',
    component:my
  },
  {
    path:'/more',
    component:more
  },
  {
    path:'/publish',
    component:publish,
    beforeEnter(to,from,next){
      if(sessionStorage.getItem('token')>=1){
        next()
      }else{
        next({
          path:'/my'
        })
      }
    }
  },
  {
    path:'/search',
    component:search
  },
  {
    path:'/detail',
    component:detail
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
